<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use Validator;
use Log;
use App\Http\Requests\TestForm;
use Illuminate\Support\Facades\Event;
use App\Events\SomeEvent;
use App\User;

class HomeController extends Controller
{
    // /**
    //  * Create a new controller instance.
    //  *
    //  * @return void
    //  */
    // public function __construct()
    // {
    //     $this->middleware('auth');
    // }


    public function welcome()
    {
        $user = User::find(1);


        //事件
        Event::fire(new SomeEvent($user));
        Log::info('hello');
        return view('welcome');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        return view('home');
    }
    public function testForm()
    {
        return view('testform');
    }
    /**
     *  表单验证
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function valiedForm(TestForm $testform)
    {

        var_dump($testform->messages);

        //验证已完成
        $name = $testform->name;
        $email = $testform->email;
        
        // $validator = Validator::make($request->all(), [
        //     'name' => 'required|max:3',
        //     'email' => 'required',
        // ]);

        // if ($validator->fails()) {
        //     var_dump($validator->messages());
        //     var_dump($validator);
        // }
        // dd($request->all());
    }
}
